home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio.more / USeqChild.cpp < prev    next >
Text File  |  1996-07-05  |  24KB  |  907 lines

  1. // USeqChild.inc.p -- call/manage child applications 
  2. // d.g.gilbert, 1991-2 
  3.  
  4. #pragma segment USeqChild
  5.  
  6. CONST
  7.             //! copied from SeqApp.app.p 
  8.     cOpenText    == 21;     //Open plain text
  9.     cOpenProj    == 22;     //Open project list
  10.     cOpenHelp    == 24;
  11.     cOpenTree == 26;
  12.  
  13.     kIsInput == FALSE;
  14.     kIsOutput == TRUE;
  15.     kDoDelete == TRUE;
  16.     kDoSave == FALSE;
  17.  
  18.     mChildren == 30;  //this is also USeqApp private global... make public here?
  19.  
  20.     kPrefViewType == 'VPrf'; // from UApp. private -- should be public 
  21.     msgMyError == 0x80001234;
  22.  
  23.  
  24. VAR
  25.     integer        gChildDialogID; //for  TChildDialog.SetPrefID 
  26.  
  27.     
  28. // TChildFile -------------------
  29.  
  30. pascal void TChildFile::IChildFile(str255 theName, OSType itsType, 
  31.                         integer        itsVRefNum, action; boolean isOutput, doDelete)
  32. VAR  aFile: TFile;
  33. {
  34.     NEW(aFile); fFile= aFile;
  35.     fFile->IFile( itsType, kSAppSig, //?! or Child sig
  36.                         true, noResourceFork, false, false);
  37.     FailOSErr( fFile->SpecifyWithTrio( itsVRefNum, 0, theName));
  38.     fAction= action;
  39.     fOutput= isOutput;
  40.     fDelete= doDelete;
  41. }
  42.  
  43. pascal void TChildFile::Free(void) // override 
  44. VAR  err: integer;
  45. {
  46.     // Test this after rest is working...
  47.     if ((fDelete)) err= fFile->DeleteFile();
  48.     TObject(fFile)= FreeIfObject( fFile);
  49.     
  50.     inherited::Free();
  51. }
  52.  
  53.  
  54.  
  55.  
  56. // TChildApp -------------------
  57.  
  58. pascal void TChildApp::IChildApp( theSN:ProcessSerialNumberPtr; TList theFiles)
  59. VAR
  60.     integer        err, vref ;
  61. {
  62.     fSN= theSN;
  63.     fFiles= theFiles;
  64. }
  65.  
  66. pascal void TChildApp::Free(void) // override 
  67. {
  68.     Ptr(fSN)= DisposeIfPtr( Ptr(fSN));
  69.     TObject(fFiles)= FreeListIfObject( fFiles);
  70.     inherited::Free();
  71. }
  72.  
  73. pascal void TChildApp::Finished(void) 
  74. // post processing by parent 
  75.  
  76.     pascal void processChildFile( TChildFile aChildF)
  77.     TList        VAR  aList;
  78.              cmd    : Integer;
  79.     {
  80.         cmd= 0;
  81.         CASE aChildF->fAction OF
  82.             kChildReturnOpenFile         :    cmd= cFinderOpen;
  83.             kChildReturnOpenSeqFile    :    cmd= cOpenProj; 
  84.             kChildReturnOpenTextFile: cmd= cOpenText; 
  85.             kChildReturnOpenTreeFile: cmd= cOpenTree;
  86.             kChildReturnOpenPictFile: gApplication->Beep(1);
  87.             kChildReturnNoAction : ;
  88.             }
  89.         if (cmd!=0)) {
  90.             //! can't use aChildF->fFile then .Free it and still have Doc free it -- Clone it
  91.             aList= NewList;
  92.             aList->InsertLast( aChildF->fFile->Clone());
  93.             gApplication->OpenOld(cmd, aList); 
  94.             aList->Free();
  95.             }
  96.     }
  97.     
  98. {
  99.     if ((fFiles!=NULL)) fFiles->Each( processChildFile);
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. pascal OSErr HandleChildDiedEvent( AppleEvent theAppleEvent, reply, Longint handlerRefCon)
  109. VAR
  110.     myErr        : OSerr;
  111.     appErr    : longint;
  112.     appSN        : ProcessSerialNumber;
  113.     DescType        returnedType ;
  114.     size        actualSize;
  115.     TChildApp        aChild ;
  116.     
  117.         pascal Boolean MatchesSN( aChild:TChildApp);
  118.         boolean        var  match ;
  119.         {        
  120.             myErr= SameProcess( aChild.(*fSN), appSN, match);
  121.             MatchesSN= match;
  122.         }
  123.     
  124. {
  125.     myErr= AEGetParamPtr( theAppleEvent, keyErrorNumber, typeLongInteger, 
  126.                         returnedType, &appErr, sizeof(appErr), actualSize);
  127.     FailOSErr(myErr);
  128.     if ((appErr == noErr)) {  
  129.         myErr= AEGetParamPtr( theAppleEvent, keyProcessSerialNumber, typeProcessSerialNumber, 
  130.                             returnedType, &appSN, sizeof(appSN), actualSize);
  131.         FailOSErr(myErr);
  132.         
  133.         TObject(aChild)= gChildList->FirstThat( MatchesSN);
  134.         if ((aChild!=NULL)) {
  135.             aChild->Finished();
  136.             gChildList->Delete(aChild);
  137.             aChild->Free();
  138.             }
  139.         }
  140.     HandleChildDiedEvent= noErr;
  141. }
  142.  
  143.  
  144.  
  145. /*usage-----------------------
  146. VAR docList: AEDescList;
  147.         boolean        firstChildFile;
  148.         
  149.     firstChildFile= TRUE;
  150.     do {
  151.         ChildOpenAddFile( firstChildFile, fileName, vRefNum, docList);
  152.         firstChildFile= FALSE;
  153.     } while (!(NoMoreFiles));
  154.     childSN= LaunchChildApp( appName, ChildOpenLaunchParams( docList));
  155. ---------------------*/
  156.  
  157.  
  158.  
  159.  
  160. //    TChildListView    -----------------
  161.  
  162. pascal void TChildListView::GetItemText( integer anItem, Str255 VAR aString) // override 
  163. VAR     aChildCommand: TChildCommand;
  164. {
  165.    aChildCommand= TChildCommand(gChildCommandList->At( anItem));
  166.      if ((aChildCommand!=NULL)) aString= aChildCommand->fMenuName
  167.      else aString= '';
  168. }
  169.  
  170.  
  171.  
  172.  
  173.  
  174. //    TEditChildWind    -----------------
  175.  
  176.  
  177. pascal void TEditChildWind::SetPrefID(void) /* override */ 
  178. {
  179.     gPrefWindID= kEditChildWindID;  
  180.     gPrefWindName= 'TEditChildWind';
  181. }
  182.  
  183.  
  184.  
  185. pascal void TEditChildWind::IEditChildWind(void)
  186. {
  187.     IPrefWindow();
  188.     fWantSave= FALSE;  
  189.         //build TTextListView data from gChildCommandList 
  190.     fListView = TTextListView( this->FindSubView('LIST'));
  191.     FailNIL( fListView);
  192.     fListView->DelItemLast( fListView->fNumOfRows);
  193.     fListView->InsItemLast( gChildCommandList->GetSize());
  194.     fEdit= TButton( FindSubView('OKAY'));
  195.     fDelete= TButton( FindSubView('DELE'));
  196. }
  197.  
  198.  
  199. pascal void TEditChildWind::DoEvent(EventNumber eventNumber, 
  200.                                             TEventHandler        source; TEvent event) // override 
  201. CONST
  202.         kDeleteMe == -12345;
  203. VAR
  204.     TEditText        aEdit;
  205.     THelpDocument        aHelpDocument;
  206.     Str255        helpName;
  207.     
  208.     pascal void EditChild( integer anItem)
  209.     VAR     aChild: TChildCommand;
  210.     {
  211.         aChild= TChildCommand(gChildCommandList->At( anItem));
  212.         if ((aChild!=NULL)) aChild->Edit();
  213.     }
  214.  
  215.     pascal void MarkChildForRemoval( integer anItem)
  216.     VAR     aChild: TChildCommand;
  217.     {
  218.         aChild= TChildCommand(gChildCommandList->At( anItem));
  219.         if ((aChild!=NULL)) aChild->fMinSeqs= kDeleteMe;
  220.     }
  221.     
  222.     pascal void RemoveMarkedChildren( TChildCommand aChild)
  223.     VAR    
  224.         integer        viewID;
  225.         MenuHandle        aMenuHandle;
  226.         integer        i;
  227.         Str255        aStr;
  228.     {
  229.         if ((aChild->fMinSeqs == kDeleteMe)) {
  230.             viewID= aChild->fViewID;
  231.             TPrefApplication(gApplication)->DeletePreference( kPrefViewType, viewID);
  232.             TPrefApplication(gApplication)->DeletePreference( 'STR#', viewID);
  233.             TPrefApplication(gApplication)->DeletePreference( 'TEXT', viewID);
  234.             TPrefApplication(gApplication)->DeletePreference( 'TEXT', 10000+viewID);
  235.                 //! must also remove from Menu...
  236.             aMenuHandle= GetMenu(mChildren);
  237.             if ((aMenuHandle!=NULL))
  238.              FOR i= 3 to CountMITems( aMenuHandle)){
  239.                 GetItem( aMenuHandle, i, aStr);
  240.                 if ((aStr == aChild->fMenuName)) {
  241.                     DelMenuItem( aMenuHandle, i);
  242.                     LEAVE();
  243.                     }
  244.                 }
  245.             gChildCommandList->Delete( aChild);
  246.             aChild->Free();
  247.             }
  248.     }
  249.  
  250. {
  251.     switch (eventNumber) {
  252.  
  253.         mButtonHit : 
  254.         
  255.             if ((source == fEdit)) {
  256.                 fListView->EachSelectedItemDo( EditChild);
  257.                 }                
  258.             else if ((source == fDelete)) {
  259.                 fListView->EachSelectedItemDo( MarkChildForRemoval);
  260.                 gChildCommandList->Each( RemoveMarkedChildren);
  261.                 }                
  262.             /*-----
  263.             else if ((source == fHelp)) {
  264.                 aEdit= TEditText( this->FindSubView('tHLP'));
  265.                 FailNIL(aEdit);
  266.                 aEdit->GetText( helpName); 
  267.                 New(aHelpDocument);
  268.                 FailNIL(aHelpDocument);
  269.                 aHelpDocument->IHelpDocument( helpName, gAppWDRef);
  270.                 TPrefApplication(gApplication)->OpenNewDocument(aHelpDocument);
  271.                 }            ----------*/
  272.             
  273.             else
  274.                 inherited::DoEvent( eventNumber, source, event);
  275.             
  276.         Otherwise {
  277.             inherited::DoEvent( eventNumber, source, event);
  278.             }
  279.         }
  280.     
  281. }
  282.  
  283.  
  284.  
  285. //    TChildDialog    -----------------
  286.  
  287. pascal void TChildDialog::IChildDialog( TChildCommand theCommand, integer theViewID, Handle cmdText, descripText)
  288. VAR
  289.     aScroller    : TScroller;
  290.     aDlog            :    TDialogView;
  291.     dlogRect    : VRect;
  292.     delta            : VPoint;
  293.     Point        minSize, maxSize;
  294. {    
  295.     IPrefWindow();
  296.     fViewID= theViewID;
  297.     fChildCommand= theCommand;
  298.     
  299.     fCommands= TDlogTextView(this->FindSubView('Cmds'));
  300.     FailNIL(fCommands);
  301.     fCommands->IDlogTextView(cmdText);
  302.     
  303.     fDescription= TDlogTextView(this->FindSubView('Desc'));
  304.     FailNIL(fDescription);
  305.     fDescription->IDlogTextView(descripText);
  306.     fHelp= TButton( this->FindSubView('HELP'));
  307.     
  308.     aDlog= TDialogView(this->FindSubView('DLOG'));
  309.     if (aDlog!=NULL) {
  310.         WITH this->fResizeLimits){
  311.             minSize = topLeft;
  312.             maxSize = botRight;
  313.             }
  314.         WITH maxSize)h = Min( 2 + aDlog->fSize.h + kSBarSizeMinus1, h);
  315.         this->SetResizeLimits(minSize, maxSize);
  316.         
  317.             //fix so prefview scroll bar shows
  318.         aDlog->GetExtent(dlogRect);
  319.         dlogRect.bottom= dlogRect.bottom+1;
  320.         ascroller= aDlog->GetScroller(FALSE);
  321.         if ((ascroller!=NULL)) 
  322.           aScroller->SetScrollLimits(dlogRect.botRight, kRedraw);
  323.         }
  324. }
  325.  
  326. pascal void TChildDialog::SetPrefID(void) /* override */ 
  327. VAR  sid: str255;
  328. {
  329.     gPrefWindID= gChildDialogID;  
  330.     NumToString( gPrefWindID, sid);
  331.     gPrefWindName= concat('Child-',sid); //!& Need unique gPrefWindName for damn TPrefWind.SaveVPref
  332. }
  333.  
  334.  
  335.  
  336.  
  337. pascal void TChildDialog::SaveEdits(void)  
  338. VAR
  339.     aEdit        : TEditText;
  340.     aNumber    : TNumberText;
  341.     TChildCommand        aChildCommand;
  342.     TControl        aControl;
  343.     aButton    : TButton;
  344.     Str255        menuName;
  345.     integer        minSeqs;
  346.     Handle        hCmds, hDesc;
  347. {
  348.     aEdit= TEditText( this->FindSubView('MENU'));
  349.     FailNIL(aEdit);
  350.     aEdit->GetText( menuName); 
  351.     
  352.     aNumber= TNumberText( this->FindSubView('iMin'));
  353.     FailNIL(aNumber);
  354.     minSeqs= aNumber->GetValue();
  355.     
  356.         //! Need to save/restore these texts w/ view, but view saver won't touch this:
  357.     hCmds= this->fCommands.(*fHTE)->hText;  
  358.     TPrefApplication(gApplication)->SetPreference('TEXT', fViewID,  hCmds);
  359.     hCmds= TPrefApplication(gApplication)->GetPreference( 'TEXT', fViewID);
  360.  
  361.     hDesc= this->fDescription.(*fHTE)->hText;  
  362.     TPrefApplication(gApplication)->SetPreference('TEXT', 10000+fViewID,  hDesc);
  363.     hDesc= TPrefApplication(gApplication)->GetPreference( 'TEXT', 10000+fViewID);
  364.     
  365.     fChildCommand->IChildCommand( menuName, fViewID, minSeqs, hCmds, hDesc);
  366. }
  367.  
  368.  
  369. pascal void TChildDialog::DisplayForLaunch(void)
  370. VAR
  371.     aView        : TView;
  372.     aEdit        : TEditText;
  373.     aNumber    : TNumberText;
  374.     TChildCommand        aChildCommand;
  375.     TControl        aControl;
  376.     aButton    : TButton;
  377.     Str255        menuName;
  378.     integer        minSeqs;
  379.     Handle        hCmds, hDesc;
  380.     aScroller    : TScroller;
  381.     aDlog            :    TDialogView;
  382.     limitPt        : VPoint;
  383. {
  384.  
  385.             //revise this Template dialog to a Launch dialog
  386.             //?? or do we just want a second Launch Dialog for display ?
  387.     fWantSave= FALSE;
  388.     this->fProcID= 5; //moveable-modal dlog; was 1?
  389.     this->SetModality(True);  
  390.     this->fIsResizable= FALSE;
  391.     this->fTargetID= 'DLOG';
  392.     this->SetTitle(''); //- SetWTitle(this->fWMgrWindow, '');  
  393.  
  394.         // make size just large enough for appname, descript, launch && cancel buttons
  395.     aView=  this->FindSubView('SubD');
  396.     //- this->fSize= aView->fSize; 
  397.     SetVpt( limitPt, aView->fSize.h  + kSBarSizeMinus1, aView->fSize.v  + kSBarSizeMinus1);
  398.     if ((aView!=NULL)) this->Resize( limitPt, TRUE);
  399.      
  400.     aDlog= TDialogView(this->FindSubView('DLOG'));
  401.     if (aDlog!=NULL) {
  402.         aScroller= aDlog->GetScroller(FALSE);
  403.         limitPt= this->fSize;
  404.         limitPt.h= 0; limitPt.v= 0;
  405.         if ((aScroller!=NULL)) 
  406.           aScroller->SetScrollLimits( limitPt, kDontRedraw);
  407.         aDlog->BeInScroller(NULL); //< no help...
  408.         //- this->RemoveSubView( aScroller);  < causes Fail 
  409.         }
  410.  
  411.     this->fCommands.fAcceptsChanges= FALSE;
  412.     this->fDescription.fAcceptsChanges= FALSE;
  413.     this->fDescription->ViewEnable( FALSE, kDontRedraw);
  414.         /*^ need to fix fDescription so it displays properly on Launch call
  415.             after NewApp call -- bad save to prefs file ??
  416.         */
  417.     
  418.     aEdit= TEditText( this->FindSubView('APPL'));
  419.     FailNIL(aEdit);
  420.     aEdit->ViewEnable( FALSE, kDontRedraw);
  421.     //- aEdit->fAdornment= [];
  422.     aEdit->DeleteAdornerByID( kFrameAdorner, kDontRedraw);
  423.     
  424.     aButton= TButton( this->FindSubView('OKAY'));
  425.     FailNIL(aButton);
  426.     aButton->SetText('Launch App', kDontRedraw);
  427. }
  428.  
  429.  
  430. pascal void TChildDialog::Edit(void)
  431. VAR        
  432.         IDType        dismisser ;
  433. {
  434.     this->ShowReverted(); /*need for TDlogText... */   
  435.     this->SetModality( True); //!!! or PoseModally will fail !
  436.     dismisser= this->PoseModally(); 
  437.     if (dismisser == 'OKAY') {
  438.         this->fWantSave= TRUE;
  439.         gChildDialogID= fViewID; //! need this in mapp3 version when fWantSave == True !
  440.         this->SaveEdits();  
  441.         }    else {
  442.         this->fWantSave= FALSE;
  443.         }
  444.     this->CloseAndFree();  
  445. }
  446.  
  447.  
  448. pascal void TChildDialog::NewChildDialog(Integer itsViewID)
  449. //!??? 2nd NewChild got same ViewID as 1st/existing Child...
  450. VAR        
  451.         menuName    : Str255;
  452.         IDType        dismisser ;
  453.         minSeqs        : integer;
  454.         Handle        hCmds, hDesc;
  455.         TChildCommand        aChildCommand;
  456.         aEdit        : TEditText;
  457.         aNumber    : TNumberText;
  458.         aControl    : TControl;
  459.         aButton        : TButton;
  460.         
  461.             //!? is gList sorted in ascending fViewID order -- then just need gList.Each... ??
  462.         pascal Boolean isIDinUse( aChildCommand:TChildCommand);
  463.         {
  464.             isIDinUse= (aChildCommand->fViewID == itsViewID);
  465.         }
  466.         
  467. {
  468.     if ((itsViewID < kNewChildTemplateID)) {
  469.         itsViewID= kNewChildTemplateID;
  470.         do { itsViewID= itsViewID+1; 
  471.         } while (!((gChildCommandList))->FirstThat( isIDinUse) == NULL);
  472.         }
  473.         
  474.     New(aChildCommand);
  475.     FailNIL( aChildCommand);
  476.     aChildCommand->IChildCommand( 'item', itsViewID, 0, NULL, NIL);
  477.  
  478.     this->IChildDialog( aChildCommand, itsViewID, NULL, NIL); 
  479.     this->ShowReverted();  //! need for TDlogText...
  480.     
  481.     this->SetModality( True); 
  482.     dismisser= this->PoseModally();
  483.     if (dismisser == 'OKAY') {
  484.         this->fWantSave= TRUE;
  485.         gChildDialogID= fViewID; //! need this in mapp3 version when fWantSave == True !
  486.         this->SaveEdits();  
  487.         gChildCommandList->InsertLast( aChildCommand);
  488.         }        
  489.     else {
  490.         this->fWantSave= FALSE;
  491.         aChildCommand->Free();
  492.         }
  493.         
  494.     this->CloseAndFree();  
  495. }
  496.  
  497.  
  498. pascal void TChildDialog::DoEvent(EventNumber eventNumber, 
  499.                                             TEventHandler        source; TEvent event) // override 
  500. VAR
  501.     TEditText        aEdit;
  502.     THelpDocument        aHelpDocument;
  503.     Str255        helpName;
  504.     fi            : FailInfo;
  505.  
  506.     pascal void HdlFail(integer error,  long message)
  507.     {
  508.         TObject(aHelpDocument)= FreeIfObject(aHelpDocument); 
  509.         //- FailNewMessage(error, message, messageInitializationFailed);  
  510.     }
  511.     
  512. {
  513.     switch (eventNumber) {
  514.  
  515.         mButtonHit : 
  516.             if ((source == fHelp)) {
  517.                 aHelpDocument= NULL;
  518.                 aEdit= TEditText( this->FindSubView('tHLP'));
  519.                 FailNIL(aEdit);
  520.                 aEdit->GetText( helpName); 
  521.                 New(aHelpDocument);
  522.                 FailNIL(aHelpDocument);
  523.                 CatchFailures(fi, HdlFail);
  524.                 aHelpDocument->IHelpDocument( helpName, gAppWDRef);
  525.                 TPrefApplication(gApplication)->OpenNewDocument(aHelpDocument);
  526.                 Success(fi);
  527.                 }            else
  528.                 inherited::DoEvent( eventNumber, source, event);
  529.             
  530.         Otherwise {
  531.             inherited::DoEvent( eventNumber, source, event);
  532.             }
  533.         }
  534. }
  535.  
  536.  
  537. pascal void TChildDialog::Launch( TSeqList selectedSeqs)
  538. VAR
  539.     aChildApp    : TChildApp;
  540.     IDType        dismisser, aNam ;
  541.     outnum        : integer;
  542.     boolean        NoMoreOutputs;
  543.     aStr            : Str255;
  544.     integer        curVolRef, aFileRef, err, nseqs;
  545.     childSN        : ProcessSerialNumberPtr;
  546.     count            : longint;
  547.     hbuf            : Handle;
  548.     
  549.     Str63        aCommandFile ;
  550.     aInFormat, aReturnAction    : integer;
  551.     aChildFile    : TChildFile;
  552.     theFiles        : TList;
  553.     okind                : OSType;
  554.     
  555.     aPopup    : TPopup;
  556.     aEdit        : TEditText;
  557.     aRadio    : TRadio;
  558.     
  559.     integer        nDocList;
  560.     docList    : AEDescList;
  561.     fi            : FailInfo;
  562.     
  563.     pascal void HdlLaunchFail(integer error,  long message)
  564.     {
  565.         if ((theFiles!=NULL)) theFiles->FreeList();  //frees childfile objects << erase files?! && list
  566.         this->CloseAndFree(); // < may be causing bombs ??
  567.         //- FailNewMessage(error, message, messageInitializationFailed); 
  568.             // this is MacApp err STR# 130 ^^^^, need own STR# errlist?
  569.     }
  570.  
  571. {
  572.     theFiles= NULL;
  573.     this->DisplayForLaunch();
  574.   this->ShowReverted();   //need for TDlogText...
  575.     this->fWantSave= FALSE;  
  576.     this->SetModality( True); 
  577.     dismisser = this->PoseModally();
  578.     
  579.     CatchFailures(fi, HdlLaunchFail);
  580.     
  581.     if (dismisser == 'OKAY') {        
  582.         nDocList= 0;
  583.         theFiles= NewList;
  584.         FailNIL( theFiles);
  585.                 
  586.         err= GetVol(NULL, curVolRef);  //!!?? need working dir here ??
  587.                 //! put us into App file location so we find subfolders...
  588.         err= SetVol( NULL, gAppWDRef);
  589.                                                                         // Look into aliases !!!
  590.         aEdit= TEditText(this->FindSubView('iNam'));
  591.         if (!((aEdit=NULL) || (selectedSeqs=NULL) || (selectedSeqs.GetSize<1))) {
  592.             aEdit->GetText(aStr); 
  593.             if (Length(aStr) > 0) {
  594.                 New( aChildFile); 
  595.                 FailNIL( aChildFile);
  596.                 aChildFile->IChildFile( aStr, 'TEXT', gAppWDRef, kChildReturnNoAction, 
  597.                                                                             kIsInput, kDoDelete);
  598.                 theFiles->InsertLast( aChildFile);
  599.                 
  600.                 aInFormat = kPearson;  
  601.                 aPopup= TPopup(this->FindSubView('iFmt'));
  602.                 if ((aPopup!=NULL)) aInFormat= aPopup->GetCurrentItem();
  603.             
  604.                 selectedSeqs->doWrite( aStr, aInFormat);
  605.                 
  606.                 ChildOpenAddFile( (nDocList=0), aStr, gAppWDRef, docList);
  607.                 nDocList= nDocList+1;
  608.                 }
  609.             }
  610.  
  611.                     //!!! NOTE: We now have many subviews w/ name 'oNam'/'oSeq'...
  612.                     // Must cycle thru them / clusterize them? / && get all return files 
  613.     outnum= 0;
  614.     do {
  615.         outnum= outnum+1;
  616.         aNam= '1Nam';
  617.         aNam[1]= ((char)(ord('0') + outnum));
  618.         aEdit= TEditText(this->FindSubView(aNam));
  619.         noMoreOutputs= aEdit == NULL;
  620.         if ((!noMoreOutputs)) {
  621.             aEdit->GetText(aStr);   
  622.             if (Length(aStr) > 0) {                
  623.                 aNam= '1Typ';
  624.                 aNam[1]= ((char)(ord('0') + outnum));
  625.                 aPopup= TPopup(this->FindSubView(aNam));
  626.                 if ((aPopup=NULL)) aReturnAction= kChildReturnOpenSeqFile
  627.                 else aReturnAction= aPopup.GetCurrentItem - 1;
  628.                 switch (aReturnAction) {
  629.                     kChildReturnOpenPictFile: okind= 'PICT';
  630.                     otherwise okind= 'TEXT';
  631.                     }
  632.                 
  633.                 if (aReturnAction != kChildReturnNoAction) {
  634.                     New( aChildFile); 
  635.                     FailNIL( aChildFile);
  636.                     aChildFile->IChildFile( aStr, okind, gAppWDRef, aReturnAction, kIsOutput, 
  637.                                                     !kDoDelete);
  638.                     theFiles->InsertLast( aChildFile);
  639.                     }
  640.                 }
  641.             }
  642.         } while (!(NoMoreOutputs)); 
  643.         
  644.         aEdit= TEditText(this->FindSubView('CmdF'));
  645.         if ((aEdit!=NULL)) {
  646.             aEdit->GetText(aStr);   
  647.             if (Length(aStr) > 0) {
  648.                 aCommandFile= aStr;
  649.                 New( aChildFile); 
  650.                 FailNIL( aChildFile);
  651.                 aChildFile->IChildFile( aCommandFile, 'TEXT', gAppWDRef, 
  652.                                                             kChildReturnNoAction, kIsInput, kDoDelete);
  653.                 theFiles->InsertLast( aChildFile);
  654.                 
  655.                 hbuf= this->fCommands.(*fHTE)->hText;
  656.                 HLock( hbuf);
  657.                 count= GetHandleSize( hbuf);
  658.                 err= FSDelete( aCommandFile, 0);   
  659.                 FailOSErr( Create( aCommandFile, 0, kSAppSig/*?*/, 'TEXT'));
  660.                 FailOSErr( FSOpen( aCommandFile, 0, aFileRef));
  661.                 FailOSErr( FSWrite( aFileRef, count, (*hbuf)));
  662.                     //make sure there is a CR at end of line/file or cmdfile may fail
  663.                 aStr[0]= ((char)(13)); count= 1;
  664.                 FailOSErr( FSWrite( aFileRef, count, &aStr[0]));
  665.                 FailOSErr( FSClose( aFileRef));
  666.                 HUnlock( hBuf);        
  667.  
  668.                 ChildOpenAddFile( (nDocList=0), aCommandFile, gAppWDRef, docList);
  669.                 nDocList= nDocList+1;
  670.                 }
  671.             }
  672.  
  673.         
  674.         childSN= NULL;
  675.         aEdit= TEditText(this->FindSubView('APPL'));
  676.         if ((aEdit!=NULL)) {
  677.             aEdit->GetText(aStr);   
  678.             if (Length(aStr) > 0) {
  679.                 if ((nDocList<1))  
  680.                     childSN= LaunchChildApp( gAppWDRef, 0, aStr, NULL)
  681.                 else
  682.                     childSN= LaunchChildApp( gAppWDRef, 0, aStr, ChildOpenLaunchParams( docList));
  683.                 }
  684.             }
  685.             
  686.         if ((childSN == NULL)) {
  687.             gApplication->Beep(1);
  688.             //LaunchChildApp should Fail w/ messages for type of failure (app not found,...) 
  689.             theFiles->FreeList();  //frees childfile objects << erase files?! && list
  690.             }        else {
  691.             New(aChildApp);
  692.             FailNIL(aChildApp);
  693.             aChildApp->IChildApp( childSN, theFiles);
  694.             gChildList->InsertLast( aChildApp);
  695.             //message: launched okay...
  696.             }
  697.             
  698.         err= SetVol( NULL, curVolRef);
  699.         }
  700.         
  701.     Success(fi);
  702.     this->CloseAndFree();
  703. }
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711. //    TChildCommand    =================================
  712.  
  713.  
  714. pascal void TChildCommand::IChildCommand( str63 name, integer viewID, minSeqs,
  715.                                     Handle aCommandsTxt, aDescriptionTxt)
  716. {
  717.     fMenuName= name;
  718.     fViewID= viewID;
  719.     fMinSeqs= MinSeqs;
  720.     fCommandsTxt= aCommandsTxt;
  721.     fDescriptionTxt= aDescriptionTxt;
  722. }
  723.  
  724.  
  725. pascal void TChildCommand::EnableMenu( MenuHandle aMenuHandle, integer nSelectedSeqs)
  726. VAR  i, atMenuItem: integer;
  727.          boolean        found;
  728.          Str255        aStr;
  729. {
  730.     found= FALSE;
  731.     FOR i= 1 to CountMITems( aMenuHandle)){
  732.         GetItem( aMenuHandle, i, aStr);
  733.         if ((aStr == fMenuName)) {
  734.             found= TRUE;
  735.             atMenuItem= i;
  736.             LEAVE();
  737.             }
  738.         }
  739.     if (!found) {
  740.         aStr= fMenuName;
  741.         AppendMenu(aMenuHandle, aStr);
  742.         atMenuItem= CountMITems( aMenuHandle); 
  743.         GetItem( aMenuHandle, atMenuItem, aStr);
  744.         fMenuName= aStr; //make sure -- MenuMgr drops "(" and others
  745.         }
  746.         
  747.     if ((nSelectedSeqs >= fMinSeqs) && gHasAppleEvents) {
  748.         if ((atMenuItem <= 31)) EnableItem(aMenuHandle, atMenuItem); 
  749.         }
  750. }
  751.  
  752.  
  753. pascal void TChildCommand::LaunchDialog( TSeqList selectedSeqs)
  754. VAR
  755.     TChildDialog        aChildDlog;
  756. {
  757.     gChildDialogID= fViewID;
  758.     aChildDlog = TChildDialog(
  759.         gViewServer->NewTemplateWindow( kNewChildTemplateID/*fViewID*/, NULL));
  760.         // 18may93:!! TRICK: ^^ don't use fViewID here which is just for VPref, not View now !!!
  761.         // BUT do use fViewID for DoPostCreate w/ View, to read in specific values...
  762.     FailNIL(aChildDlog);          
  763.     aChildDlog->IChildDialog( this, fViewID, fCommandsTxt, fDescriptionTxt);
  764.     aChildDlog->Launch( selectedSeqs);
  765. }
  766.  
  767. pascal void TChildCommand::Edit(void)
  768. VAR
  769.     TChildDialog        aChildDlog;
  770. {
  771.     gChildDialogID= fViewID;
  772.     aChildDlog = TChildDialog( 
  773.         gViewServer->NewTemplateWindow( kNewChildTemplateID/*fViewID*/, NULL));
  774.         // 18may93:!! TRICK: ^^ don't use fViewID here which is just for VPref, not View now !!!
  775.         // BUT do use fViewID for DoPostCreate w/ View, to read in specific values...
  776.     FailNIL(aChildDlog); 
  777.     aChildDlog->IChildDialog( this, fViewID, fCommandsTxt, fDescriptionTxt);
  778.     aChildDlog->Edit();
  779. }
  780.  
  781.  
  782.  
  783.  
  784. pascal void OpenNewChild(void)
  785. VAR  aChildDlog : TChildDialog;  
  786. {
  787.     if (!gHasAppleEvents) {
  788.         ParamText('System-7 && AppleEvents are not installed',
  789.                             '', 'Children','');    
  790.         Failure( -1, msgMyError);  //takes us out of proc...
  791.         Exit(OpenNewChild);
  792.         }
  793.         
  794.     aChildDlog = TChildDialog(
  795.         gViewServer->NewTemplateWindow(kNewChildTemplateID, NULL));
  796.     FailNIL(aChildDlog);          
  797.     aChildDlog->NewChildDialog( 0);  
  798.     // gChildDialogID= aChildDlog->fViewID;??
  799. }
  800.  
  801.  
  802.  
  803. pascal void InitChildApps( boolean hasAppleEvents)  //call from gApplication.IApplication
  804. CONST
  805.     MaxViewID ==  kNewChildTemplateID+200;
  806. VAR
  807.     integer        nextViewID;
  808.     TChildDialog        aChildDlog;
  809.     Str255        menuName;
  810.     minSeqs    : integer;
  811.     TChildCommand        aChildCommand;
  812.     h            : Handle;
  813.     aCommandsTxt, 
  814.     aDescriptionTxt    : Handle;
  815.     TEditText        aEdit;
  816.     TNumberText        aNumber;
  817.     
  818. {
  819.     gHasAppleEvents= hasAppleEvents;
  820.     if (!hasAppleEvents) {
  821.         gChildList= NULL;
  822.         gChildCommandList= NULL;
  823.         exit(InitChildApps);
  824.         }
  825.         
  826.     gChildList= NewList;
  827.     FailNIL(gChildList);
  828.     gChildCommandList= NewList;
  829.     FailNIL(gChildCommandList);
  830.     
  831.     //! Read ChildCommandList from Prefs resources....
  832.     // views start at kNewChildTemplateID+1 
  833.  
  834.     nextViewID= kNewChildTemplateID; /*getsize=0*/ 
  835.     do {
  836.         nextViewID= nextViewID + 1;
  837.         h= GetResource(kPrefViewType, nextViewID);
  838.         if (h!=NULL) {
  839.             //?? ReleaseResource( h); ??
  840.             gChildDialogID= nextViewID; 
  841.                 //!! ^^ 18may93: so TChildDialog/TPrefs->DoPostCreate() reads right vals
  842.             aChildDlog = TChildDialog(
  843.                 gViewServer->NewTemplateWindow(kNewChildTemplateID/*nextViewID*/, NULL));
  844.                 //!! 18may93: TRICK: ^^ don't use nextViewID here which is just for VPref, not View now !!!
  845.                 // BUT do use nextViewID=gChildDialogID for DoPostCreate w/ View, to read in specific values...
  846.             FailNIL(aChildDlog);
  847.             aChildDlog->IChildDialog( NULL, nextViewID, NULL, NIL); /*<< use aCommandsTxt,aDescText for NILs?*/ 
  848.             
  849.             NumToString( nextViewID, menuName);
  850.             menuName= concat('Task ',menuName);
  851.             aEdit= TEditText( aChildDlog->FindSubView('MENU'));
  852.             if ((aEdit!=NULL)) aEdit->GetText( menuName); 
  853.     
  854.             minSeqs= 0;
  855.             aNumber= TNumberText( aChildDlog->FindSubView('iMin'));
  856.             if ((aNumber!=NULL)) minSeqs= aNumber->GetValue();
  857.             
  858.             aCommandsTxt     = 
  859.                 TPrefApplication(gApplication)->GetPreference( 'TEXT', nextViewID);
  860.             aDescriptionTxt= 
  861.                 TPrefApplication(gApplication)->GetPreference( 'TEXT', 10000+nextViewID);
  862.  
  863.             New(aChildCommand);
  864.             FailNIL( aChildCommand);
  865.             aChildCommand->IChildCommand( menuName, nextViewID, minSeqs, 
  866.                                                                             aCommandsTxt, aDescriptionTxt);
  867.             gChildCommandList->InsertLast( aChildCommand);
  868.         
  869.             aChildDlog->fWantSave= FALSE;    
  870.             aChildDlog->Free(); //? or close? but never opened...
  871.             }
  872.     } while (!((nextViewID >= MaxViewID))); 
  873.                     //^^ look thru 100 id's, allow for removals
  874.                     
  875.     if (gDeadStripSuppression) {
  876.         if (Member(TObject(NULL), TChildListView));
  877.         if (Member(TObject(NULL), TEditChildWind));
  878.         if (Member(TObject(NULL), TChildCommand));
  879.         if (Member(TObject(NULL), TChildDialog));
  880.         if (Member(TObject(NULL), TChildApp));
  881.         }
  882.         
  883. }
  884.  
  885.  
  886. pascal void OpenEditChild(void)
  887. VAR aWind    : TEditChildWind; boolean isNowOpen,
  888.  
  889.     pascal void checkOpenWind( TWindow aWind)
  890.     {
  891.         if (Member(TObject(aWind), TEditChildWind)) { 
  892.             aWind->Select(); 
  893.             isNowOpen= TRUE;
  894.             }
  895.     }
  896. {
  897.     isNowOpen= FALSE;
  898.     gApplication->ForAllWindowsDo(checkOpenWind);
  899.     if (!isNowOpen) {
  900.         aWind = TEditChildWind(gViewServer->NewTemplateWindow(kEditChildWindID, NULL));
  901.         FailNIL(aWind);          
  902.         aWind->IEditChildWind();  
  903.         aWind->ShowReverted();   
  904.         aWind->Open();  
  905.         }
  906. }
  907.